package com.vast.controller;


import com.alibaba.fastjson.JSON;
import com.vast.entity.BorrowerEntity;
import com.vast.entity.RepaymentEntity;
import com.vast.pojo.Result;
import com.vast.pojo.StatusCode;
import com.vast.service.RepaymentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/repayment")
public class RepaymentController {

    @Autowired
    RepaymentService repaymentService;

    /**
     * 通过借款信息ID查询数据
     * @param borrowId
     * @param states
     * @return
     */
    @GetMapping("/getByBorrowId")
    public Result getByBorrowId(@RequestParam("borrowId") Integer borrowId,@RequestParam("states") Integer states){
       List<RepaymentEntity> list= repaymentService.getByBorrowId(borrowId,states);
        return  new Result(StatusCode.OK,"查询还款信息成功",true,list);
    }


    /**
     * 部分还款接口
     * @param map
     * @return
     */
    @PostMapping("/saveBuFen")
    public Result saveBuFen(@RequestBody Map<String,Object> map){
         List<RepaymentEntity> list= repaymentService.saveBuFen(map);
        return  new Result(StatusCode.OK,"查询还款信息成功",true,list);
    }

    /**
     * 根据还款计化ID修改状态
     * @param repayId
     * @return
     */
    @GetMapping("/getByRepayId")
    public Result getByRepayId(@RequestParam("repayId") Integer repayId,@RequestParam("overdue") Integer overdue,@RequestParam("borrowId") Integer borrowId){
        repaymentService.updateStatesByRepayId(repayId,overdue,borrowId);
        return  new Result(StatusCode.OK,"还款成功",true);
    }

    /**
     * 提前全部结清按钮
     * @param borrowId
     * @param states
     * @return
     */
    @GetMapping("/updateByBorrowId")
    public Result updateByBorrowId(@RequestParam("borrowId") Integer borrowId,@RequestParam("states") Integer states){
         repaymentService.updateByBorrowId(borrowId,states);
        return  new Result(StatusCode.OK,"提前全部结清成功",true);
    }

    /**
     * 通过借款用户ID查询数据
     * @param userId
     * @return
     */
    @GetMapping("/getUserByBorrowId")
    public Result getUserByBorrowId(@RequestParam("userId") String userId){
        List<RepaymentEntity> list= repaymentService.getUserByBorrowId(userId);
        return  new Result(StatusCode.OK,"查询还款信息成功",true,list);
    }
}
